import { LAYER_CHANGE_TYPE } from "../common/GameConfig";
import EventManager from "../core/event/EventManager";
import { Event_Name } from "../core/event/event_mgr";


const { ccclass, property } = cc._decorator;

@ccclass
export default class Main extends cc.Component {

    @property(cc.Node)
    welcomeLayer: cc.Node = null;
    @property(cc.Node)
    gameLayer: cc.Node = null;
    @property(cc.Node)
    overLayer: cc.Node = null;
    @property(cc.Node)
    topMask: cc.Node = null;

    // @property
    // text: string = 'hello';

    onLoad() {
        this.initLayer();
        this.node.on('show_Main', this.showMain, this);
        this.node.on('show_home', this.initLayer, this);
    }

    protected onEnable(): void {
        EventManager.Instance.on(Event_Name.LAYER_CHANGE, this.onLayerChange, this);
    }

    protected onDisable(): void {
        EventManager.Instance.off(Event_Name.LAYER_CHANGE, this.onLayerChange, this);
    }

    start() {

    }

    private initLayer() {
        this.welcomeLayer.active = true;
        this.gameLayer.active = false;
        this.overLayer.active = false;
        this.topMask.active = false;
    }

    private showMain() {
        cc.find('welcomeLayer', this.node).active = false;
        cc.find('mainLayer', this.node).active = true;
        cc.find('gameoverLayer', this.node).active = false;
    }

    private showOver() {
        cc.find('welcomeLayer', this.node).active = false;
        cc.find('gameoverLayer', this.node).active = true;
    }

    private onLayerChange(type: LAYER_CHANGE_TYPE) {
        switch (type) {
            case LAYER_CHANGE_TYPE.WELCOME_TO_GAME:
                this.gameLayer.active = true;
                this.welcomeLayer.active = false;
                this.overLayer.active = false;
                break;
            case LAYER_CHANGE_TYPE.WELCOME_TO_OVER:
                break;
            case LAYER_CHANGE_TYPE.GAME_TO_OVER:
                this.overLayer.active = true;
                break;
            case LAYER_CHANGE_TYPE.OVER_TO_WELCOME:
                this.initLayer();
                break;
            case LAYER_CHANGE_TYPE.OVER_TO_GAME:
                break;

            default:
                break;
        }
    }


    // update (dt) {}
}
